﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Uinside.CreditSystem.DomainModels.Models
{
    public class BaseModel : INotifyPropertyChanged
    {
        private int _id;
        [Key]
        public int Id
        {
            get { return _id; }
            set { SetField(ref _id, value, "Id"); }
        }

        //private Employee _employee;
        //public Employee Employee
        //{
        //    get { return _employee; }
        //    set { SetField(ref _employee, value, "Employee"); }
        //}


        protected bool SetField<T>(ref T field, T value, string propertyName)
        {
            if (EqualityComparer<T>.Default.Equals(field, value)) return false;
            field = value;
            OnPropertyChanged(propertyName);
            return true;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
